package net.mysoft.budgetsoft.system.action;

import java.util.List;

import javax.annotation.Resource;

import net.mysoft.budgetsoft.system.domain.TXiTongXX;
import net.mysoft.budgetsoft.system.pagemodel.XiTongXX;
import net.mysoft.budgetsoft.system.service.XiTongXXService;
import net.mysoft.framework.base.BaseAction;
import net.mysoft.framework.model.Json;
import net.mysoft.framework.model.SessionInfo;
import net.mysoft.framework.util.ExceptionUtil;
import net.mysoft.framework.util.ResourceUtil;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ModelDriven;

/**
 * 
 * @author dagongPGP v1.0
 * @link <a href=http://www.dagongsoft.net>北京大公信软科技有限公司</a>
 * 
 * @version $Revision: 1.00 $Date: 2014-01-11 18:03:54
 */
@Action(value = "xiTongXXAction", results = { 
		@Result(name = "weiYueXX", location = "/platform/layout/portal/weiYueXX.jsp"), 
		@Result(name = "allWYXX", location = "/platform/system/allWYXX.jsp"), 
		@Result(name = "yiYueXX", location = "/platform/layout/portal/yiYueXX.jsp"), 
		@Result(name = "allYYXX", location = "/platform/system/allYYXX.jsp") 
		
})
@Controller("xiTongXXAction")
public class XiTongXXAction extends BaseAction implements ModelDriven<XiTongXX> {

	private static final Logger logger = Logger.getLogger(XiTongXXAction.class);
	@Resource
	private XiTongXXService xiTongXXService;

	private List<XiTongXX> xiTongXXList;

	public List<XiTongXX> getXiTongXXList() {
		return xiTongXXList;
	}

	public void setXiTongXXList(List<XiTongXX> xiTongXXList) {
		this.xiTongXXList = xiTongXXList;
	}

	private XiTongXX xiTongXX = new XiTongXX();

	public XiTongXXService getXiTongXXService() {
		return this.xiTongXXService;
	}

	public void setXiTongXXService(XiTongXXService xiTongXXService) {
		this.xiTongXXService = xiTongXXService;
	}

	public XiTongXX getXiTongXX() {
		return this.xiTongXX;
	}

	public void setXiTongXX(XiTongXX xiTongXX) {
		this.xiTongXX = xiTongXX;
	}

	public XiTongXX getModel() {
		return xiTongXX;
	}

	/**
	 * 首页 -- 未阅消息页面
	 * 
	 * @return
	 */
	public String weiYueXX() {
		SessionInfo sessionInfo = (SessionInfo) super.getSession().getAttribute(ResourceUtil.getSessionInfoName());
		xiTongXX.setToId(sessionInfo.getUserId());
		xiTongXX.setZhuangTai(TXiTongXX.WEIYUE);
		xiTongXX.setPage(1);
		xiTongXX.setRows(4);
		xiTongXXList = xiTongXXService.datagrid(xiTongXX).getRows();
		return "weiYueXX";
	}

	/**
	 * 查看更多未阅信息页面
	 * 
	 * @return
	 */
	public String allWYXX() {
		return "allWYXX";
	}

	/**
	 * 首页 -- 已阅消息页面
	 * 
	 * @return
	 */
	public String yiYueXX() {
		SessionInfo sessionInfo = (SessionInfo) super.getSession().getAttribute(ResourceUtil.getSessionInfoName());
		xiTongXX.setToId(sessionInfo.getUserId());
		xiTongXX.setZhuangTai(TXiTongXX.YIYUE);
		xiTongXX.setPage(1);
		xiTongXX.setRows(4);
		xiTongXXList = xiTongXXService.datagrid(xiTongXX).getRows();

		return "yiYueXX";
	}

	/**
	 * 查看更多已阅消息页面
	 * 
	 * @return
	 */
	public String allYYXX() {
		return "allYYXX";
	}

	/**
	 * 标记为已阅
	 */
	public void seen() {
		Json j = new Json();
		try {
			xiTongXXService.seen(xiTongXX);
			j.setSuccess(true);
			j.setMsg("标记成功！");
		} catch (Exception e) {
			logger.error(ExceptionUtil.getExceptionMessage(e));
			j.setMsg("标记失败！");
		}
		super.writeJson(j);
	}

	/**
	 * 邮件删除（假删除）
	 */
	public void del() {
		Json j = new Json();
		try {
			xiTongXXService.del(xiTongXX);
			j.setSuccess(true);
			j.setMsg("删除成功！");
		} catch (Exception e) {
			logger.error(ExceptionUtil.getExceptionMessage(e));
			j.setMsg("删除失败！");
		}
		super.writeJson(j);
	}

	/**
	 * 统计未读消息的数目
	 */
	public void magCount() {
		try {
			super.writeJson(xiTongXXService.msgCount(xiTongXX));
		} catch (Exception e) {
			logger.error(ExceptionUtil.getExceptionMessage(e));
			e.printStackTrace();
		}
	}

	/**
	 * 获取催办信息
	 */
	public void huoQuCBXX() {
		Json j = new Json();
		try {
			j.setSuccess(true);
			j.setMsg("dddd");
			j.setObj(xiTongXXService.huoQuCBXX(xiTongXX));
		} catch (Exception e) {
			logger.error(ExceptionUtil.getExceptionMessage(e));
			e.printStackTrace();
		}
		super.writeJson(j);
	}

	/**
	 * 列表
	 */
	public void datagrid() {
		try {
			super.writeJson(xiTongXXService.datagrid(xiTongXX));
		} catch (Exception e) {
			logger.error(ExceptionUtil.getExceptionMessage(e));
		}
	}

}
